import time
import random
from selenium.webdriver.support import expected_conditions as EC

from numpy.random import random
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait

from commom.Utils import WebChatDriver


class WebChatFriendList:
    driver=""
    url=""
    def __init__(self):
        self.driver=WebChatDriver.driver
        self.url="http://127.0.0.1:8080/client.html"


    #测试登录界面下
    def ListTestByLogin(self):
        print("----测试登录下的好友界面----")
        #点击好友界面
        self.driver.find_element(By.CSS_SELECTOR,"body > div.client-container > div > div.left > div.tab > div.tab-friend").click()
        WebChatDriver.getScreeShot()
        text=self.driver.find_element(By.CSS_SELECTOR,"#friend-list > li > h4").text
        assert text=="zhangsan"
        #点击好友列表的人物跳转到聊天页，并且能发送消息
        self.driver.find_element(By.CSS_SELECTOR,"#friend-list > li > h4").click()
        key="123456"
        wait = WebDriverWait(self.driver, 10)
        textarea_element = wait.until(
            EC.element_to_be_clickable((By.CSS_SELECTOR, "body > div.client-container > div > div.right > textarea")))
        textarea_element.send_keys(key)
        print("发送消息："+key)
        self.driver.find_element(By.CSS_SELECTOR,"body > div.client-container > div > div.right > div.ctrl > button").click()
        # self.driver.find_element(By.CSS_SELECTOR,"#session-list > li.selected > h3").click()
        time.sleep(2)
        # # 获取元素的文本内容
        # text = self.driver.find_element(By.CSS_SELECTOR, "body > div.client-container > div > div.right > div.message-show > div > div > p").text
        # assert text==key
        #将消失发出并截图
        WebChatDriver.getScreeShot()
        print("----测试登录下的好友界面[pass]----\n")


